![]() |
||||
Working With Functions (Continues) OPENING QUESTION: Take a look at this code: The "main program" and the "function". What happens when MAIN is run?
It's a little bit weird (I intentionally named it something non-sensical, please don't do that when you're coding), but see if you can identify how I'm *sending* information into the function...
LEARNING TARGET: I will SUCCESSFULLY create a command function and a predicate function during today's class.
═══════════════════════════ WORDS O' THE DAY: Parameter
WORK O' THE DAY: Please write a function that: 1) accepts an integer number as an argument 2) Says:
3) Does NOT return any values. ═══════════════════════════ Now let's spend some time talking about those pesky arguments (or parameters if you like, either name will do) Pretty much all computer languages allow you to SEND IN as many arguments as you like. However, you can ONLY return one value back to the calling program. You can, however, make changes to the arguments inside your function, but we'll talk about that another day. Take a look at this code:
═══════════════════════════
HINT: We will begin commenting our code (see below) starting today! It might be helpful to know that "concatenate" means to join separate variables into one longer 'string' of terms. When would a function like this be really, really helpful? I made a wee change between the two screen shots... can you find it? Why did I do that?
There is a way to actually send SNAP code to each other via text files. It can be a bit odd but see if you can import this function(xml) or HERE (shared) into your own file and write a program that successfully CALLS that function. Fix any bugs you find but DO NOT make substantial changes to the function
|
||||